fix(unpickler): allow Alpha158/Alpha360 handlers and the standard dataset chain#2213
Open
genisis0x wants to merge 1 commit into
Open
fix(unpickler): allow Alpha158/Alpha360 handlers and the standard dataset chain#2213genisis0x wants to merge 1 commit into
genisis0x wants to merge 1 commit into
Conversation
…aset chain The RestrictedUnpickler safelist introduced by the recent security hardening (microsoft#2099 / microsoft#2076 / microsoft#2153) only covered the abstract ``DataHandler`` / ``DataHandlerLP`` classes plus ``StaticDataLoader``. Any rolling workflow that pickles a real Dataset (the default for ``Rolling._train_rolling_tasks``) walks into one of the contrib stock handlers and now crashes on reload (issue microsoft#2130): UnpicklingError: Forbidden class: qlib.contrib.data.handler.Alpha158. Only whitelisted classes are allowed for security reasons. ... Unrolling workflows happened to use a path that did not go through the restricted loader, which is why downgrading to 0.9.7 hid the issue. Extend ``SAFE_PICKLE_CLASSES`` with the qlib-internal classes that sit on the standard recorder pickle graph: * The four shipped contrib handlers: ``Alpha158``, ``Alpha158vwap``, ``Alpha360``, ``Alpha360vwap``. * The dataset wrappers (``Dataset``, ``DatasetH``, ``TSDatasetH``) and the additional concrete loaders (``DataLoader``, ``DLWParser``, ``QlibDataLoader``, ``NestedDataLoader``, ``DataLoaderDH``). * Every concrete ``Processor`` defined in ``qlib.data.dataset.processor`` -- they show up in every realistic ``learn_processors`` / ``infer_processors`` chain. These are all classes already shipped inside qlib itself, so adding them does not weaken the threat model the safelist was designed against (arbitrary code execution through external pickle payloads). Add regression tests pinning each added entry plus an end-to-end check that ``RestrictedUnpickler.find_class`` actually resolves ``Alpha158`` and that other unknown classes are still rejected. Fixes microsoft#2130
Author
|
Reviewed the CLA, happy to sign. @microsoft-github-policy-service agree |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes UnpicklingError: Forbidden class: qlib.contrib.data.handler.Alpha158 #2130. The RestrictedUnpickler safelist landed by the recent security hardening (fix(security): address reported unsafe pickle.load usages #2099 / fix(security): restrict pickle deserialization to safe classes #2076 / fix(security): use RestrictedUnpickler in load_instance #2153) only covered the abstract
DataHandler/DataHandlerLPclasses plusStaticDataLoader. Any rolling workflow that pickles a real Dataset (the default forRolling._train_rolling_tasks) walks into one of the contrib stock handlers and now crashes on reload:Unrolling workflows happened to use a path that did not go through the restricted loader, which is why downgrading from
0.9.8.dev26to0.9.7hid the issue.Extend
SAFE_PICKLE_CLASSESwith the qlib-internal classes that sit on the standard recorder pickle graph:Alpha158,Alpha158vwap,Alpha360,Alpha360vwap.Dataset,DatasetH,TSDatasetH) and the additional concrete loaders (DataLoader,DLWParser,QlibDataLoader,NestedDataLoader,DataLoaderDH).Processordefined inqlib.data.dataset.processor-- they appear in every realisticlearn_processors/infer_processorschain.These are all classes already shipped inside qlib itself, so adding them does not weaken the threat model the safelist was designed against (arbitrary code execution through externally-supplied pickle payloads).
Validation
uv run pytest tests/misc/test_pickle_safelist.py tests/misc/test_config_registered.py-- 13 passed (25 subtests).uv run black qlib/utils/pickle_utils.py tests/misc/test_pickle_safelist.py -l 120 --check --diff-- clean.uv run flake8 --ignore=E501,F541,E266,E402,W503,E731,E203 qlib/utils/pickle_utils.py-- clean.RestrictedUnpickler.find_class("qlib.contrib.data.handler", "Alpha158")now returns the realAlpha158class object instead of raising, and a payload containing an unrelated unknown class is still rejected.Fixes #2130